import type {
  ManageVO,
  ManageForm,
  ManageQuery,
  TimeEventLine,
  TimeEventQuery,
  PatientHealthData,
} from './model';

import type { ID, IDS } from '#/api/common';
import type { PageResult } from '#/api/common';

import { commonExport } from '#/api/helper';
import { requestClient } from '#/api/request';

/**
 * 查询患者用户列表
 * @param params
 * @returns 患者用户列表
 */
export function manageList(params?: ManageQuery) {
  return requestClient.get<PageResult<ManageVO>>('/business/enrollment/list', {
    params,
  });
}

/**
 * 导出患者用户列表
 * @param params
 * @returns 患者用户列表
 */
export function manageExport(params?: ManageQuery) {
  return commonExport('/business/enrollment/export', params ?? {});
}

/**
 * 查询患者用户详情
 * @param userId id
 * @returns 患者用户详情
 */
export function manageInfo(userId: ID) {
  return requestClient.get<ManageVO>(`/business/enrollment/${userId}`);
}

/**
 * 新增患者用户
 * @param data
 * @returns void
 */
export function manageAdd(data: ManageForm) {
  return requestClient.postWithMsg<void>('/business/enrollment', data);
}

/**
 * 更新患者用户
 * @param data
 * @returns void
 */
export function manageUpdate(data: ManageForm) {
  return requestClient.putWithMsg<void>('/business/enrollment', data);
}

/**
 * 删除患者用户
 * @param userId id
 * @returns void
 */
export function manageRemove(userId: ID | IDS) {
  return requestClient.deleteWithMsg<void>(`/business/enrollment/${userId}`);
}

/**
 * 删除患者用户
 * @param userId id
 * @returns void
 */
export function manageApprove(enrollmentIds: ID | IDS) {
  return requestClient.postWithMsg<void>(
    `/business/enrollment/approve/${enrollmentIds}`,
  );
}

/**
 * 获取患者入组详细信息
 * @param userId id
 * @returns void
 */
export function getPatientInfo(enrollmentId: ID | IDS) {
  return requestClient.get<ManageVO>(`/business/enrollment/${enrollmentId}`);
}

/**
 * 获取患者入组后干预要点
 * @param userId id
 * @returns void
 */
export function timelineEventInfo(params: TimeEventQuery) {
  return requestClient.get<TimeEventLine[]>(`/business/timelineEvent/list`, {
    params,
  });
}

/**
 * 获取患者最新生命体征
 * @param userId id
 * @returns void
 */
export function latestVitalsInfo(patientId: string) {
  return requestClient.get<PatientHealthData>(
    `/business/user/latest-vitals/${patientId}`,
  );
}
